historyRecord = {
  initPage:function() {
    this.data = {
      pageNum: 1,
      tableData: [],
      queryData: {
        page: 1,
        size: 10,
      },
      queryDialogData: {
        vehicleNo: "",
        commandCode: "",
        sendTime: ""
      },
      cursorType: "",
      clpzFontColor: "",
      ptcgFontColor: "",
      yhcgFontColor: "",
      cgDialogData: [],
      pzDialogData: [],
      columnPlatRecord: [
        {
          field: 'no',
          title: '序号',
          align: 'center',
					formatter: function (value, row, index) {
            var pageSize = historyRecord.data.queryData.size;
            var pageNumber = historyRecord.data.queryData.page;
            return pageSize * (pageNumber - 1) + index + 1;
          }
        },
        {
          field: "platformName",
          title: "平台名称",
        },
        {
          field: "accessCode",
          title: "平台接入码",
        },
        {
          field: "objectType",
          title: "对象类型",
        },
        {
          field: "commandCodeName",
          title: "交互类型",
          formatter: historyRecord.operateFormatterCheckPlatform,
          events:window.operateEvents = {
            'click #checkPlatform': function (e, value, row, index) {
              if (row.ackContent === "请求成功" && row.commandCode === "0x9301") {
                $("#cgDialog").show(); // 查岗模态框
                historyRecord.getCheckPlatData(row);
              }
            }
          },
        },
        {
          field: "sendContent",
          title: "信息内容",
        },
        {
          field: "sendTime",
          title: "信息时间",
        },
        {
          field: "ackContent",
          title: "响应状态",
        },
        {
          field: "ackTime",
          title: "响应时间",
        }
      ],
      columnOwerRecord: [
        {
          field: 'no',
          title: '序号',
          align: 'center',
					formatter: function (value, row, index) {
            var pageSize = historyRecord.data.queryData.size;
            var pageNumber = historyRecord.data.queryData.page;
            return pageSize * (pageNumber - 1) + index + 1;
          }
        },
        {
          field: "platformName",
          title: "业户名称",
        },
        {
          field: "objectType",
          title: "对象类型",
        },
        {
          field: "commandCodeName",
          title: "交互类型",
          formatter: historyRecord.operateFormatterCheckOwers,
          events:window.operateEvents = {
            'click #checkOwers': function (e, value, row, index) {
              if (row.ackContent === "请求成功" && row.commandCode === "0x9301") {
                $("#cgDialog").show(); // 查岗模态框
                historyRecord.getCheckOwersData(row);
              }
            }
          },
        },
        {
          field: "sendContent",
          title: "信息内容",
        },
        {
          field: "sendTime",
          title: "信息时间",
        },
        {
          field: "ackContent",
          title: "响应状态",
        },
        {
          field: "ackTime",
          title: "响应时间",
        }
      ],
      columnVehicleRecord: [
        {
          field: 'no',
          title: '序号',
          align: 'center',
					formatter: function (value, row, index) {
            var pageSize = historyRecord.data.queryData.size;
            var pageNumber = historyRecord.data.queryData.page;
            return pageSize * (pageNumber - 1) + index + 1;
          }
        },
        {
          field: "platformName",
          title: "车牌号码",
        },
        {
          field: "accessCode",
          title: "消息来源",
        },
        {
          field: "commandCodeName",
          title: "消息类型",
          formatter: historyRecord.operateFormatterVehicle,
          events:window.operateEvents = {
            'click #commandType': function (e, value, row, index) {
              if (row.ackContent === "请求成功" && row.commandCode === "0x9502") {
                $("#photoDialog").show(); // 拍照模态框
                historyRecord.getPZDialogData(row);
              }
            }
          },
        },
        {
          field: "sendContent",
          title: "请求内容",
        },
        {
          field: "sendTime",
          title: "请求时间",
        },
        {
          field: "ackContent",
          title: "应答内容",
        },
        {
          field: "ackTime",
          title: "应答时间",
        }
      ],
    },
    this.initTime();
    this.getPlatTableData();
    this.btnEvent();
    this.selectedValue();
  },
  initTime() {
    //时分年月日范围
    $('.J-datepickerTime-range').datePicker({
      format: 'YYYY-MM-DD HH:mm',
      isRange: true
    });
    this.setTimeDefault();
  },
  /**
   * 设置默认时间
   */
  setTimeDefault() {
    var startTime = moment().subtract(7, 'days').format('YYYY-MM-DD HH:mm');
    var lateDay = moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm');
    $(".timeselect_start").val(startTime);
    $(".timeselect_end").val(lateDay);
  },
  /**
   * 获取查询参数
   */
  getQueryData() {
    var queryData = {};
    switch(this.data.pageNum ) {
      case 1:
        queryData.page = this.data.queryData.page;
        queryData.size = this.data.queryData.size;
        queryData.platformName = $(".platOWerVeh_name input").val().trim();
        queryData.platformcode = $(".platform_code input").val();
        queryData.hangyeType = $(".interaction_type .combo-select .combo-dropdown li.option-selected").index(); // 交互类型
        queryData.startTime = $(".timeselect_start").val();
        queryData.endTime = $(".timeselect_end").val();
        break;
      case 2:
        queryData.page = this.data.queryData.page;
        queryData.size = this.data.queryData.size;
        queryData.owersName = $(".platOWerVeh_name input").val().trim();
        queryData.hangyeType = $(".interaction_type .combo-select .combo-dropdown li.option-selected").index();
        queryData.startTime = $(".timeselect_start").val();
        queryData.endTime = $(".timeselect_end").val();
        break;
      case 3:
        queryData.page = this.data.queryData.page;
        queryData.size = this.data.queryData.size;
        // queryData.hangyeType = $(".message_from .combo-select .combo-dropdown li.option-selected").index(); // 消息来源
        queryData.platformcode = $("#message_type option:selected").val(); // 消息类型
        queryData.vehicleNo = $(".platOWerVeh_name input").val().trim();
        queryData.startTime = $(".timeselect_start").val();
        queryData.endTime = $(".timeselect_end").val();
        break;
    }
    return queryData
  },
  resetQueryData() { // 重置
    this.data.queryData.page = 1;
    $(".platOWerVeh_name input").val('');
    $(".platform_code input").val('');
    $(".interaction_type .combo-select .combo-dropdown li:first-child").addClass("option-selected").siblings().removeClass("option-selected"); // 抽检类型
    $(".interaction_type .combo-select .combo-input").val("全部");
    $(".message_type .combo-select .combo-dropdown li:first-child").addClass("option-selected").siblings().removeClass("option-selected"); // 抽检类型
    $(".message_type .combo-select .combo-input").val("全部");
    $(".message_from .combo-select .combo-dropdown li:first-child").addClass("option-selected").siblings().removeClass("option-selected"); // 抽检类型
    $(".message_from .combo-select .combo-input").val("全部");
    $(".timeselect_start").val('');
    $(".timeselect_end").val('');
    this.setTimeDefault();
  },
  /**
   * 表格初始化
   */
  initBootTable(data,columns,total) {
    $('#cnf_reportTable').bootstrapTable({
      method: 'get',
      cache: false,
      height: 420,
      pagination: true,
      pageSize: historyRecord.data.queryData.size,
      pageNumber:historyRecord.data.queryData.page,
      pageList: [10, 25, 50, 100],
      showColumns: true,
      striped: true,
      columns: columns,
      data :data,
      sidePagination: 'server', // client or server
      totalRows: total,
      onPageChange: function (size, number) {
        historyRecord.data.queryData.size = size;
        historyRecord.data.queryData.page = number;
        historyRecord.queryTableData();
      },
      // onClickCell: function (field, value, row, $element) {
      //   console.log("单元格点击事件")
      //   console.log(field)
      //   console.log(value)
      //   console.log(row)
      //   console.log($element)
      // },
      formatNoMatches: function(){
          return '暂无数据';
      }
    });
  },
  getPlatTableData() { // 平台交互记录
    jrequest.get("/api/commendSend/platform",this.getQueryData()).then(res => {
      $("#cnf_reportTable").bootstrapTable('destroy');
      this.initBootTable(res.data,this.data.columnPlatRecord,res.total);
    })
  },
  getOwerTableData() { // 业户交互记录
    jrequest.get("/api/commendSend/owser",this.getQueryData()).then(res => {
      $("#cnf_reportTable").bootstrapTable('destroy');
      this.initBootTable(res.data,this.data.columnOwerRecord,res.total);
    })
  },
  getVehicTableData() { // 车辆交互记录
    jrequest.get("/api/commendSend/vehicle",this.getQueryData()).then(res => {
      $("#cnf_reportTable").bootstrapTable('destroy');
      this.initBootTable(res.data,this.data.columnVehicleRecord,res.total);
    })
  },
  /**
   * 获取 查岗 拍照 模态框数据
   */
  getPZDialogData(row) {
    this.data.queryDialogData.vehicleNo = row.platformName;
    this.data.queryDialogData.commandCode = row.commandCode;
    this.data.queryDialogData.sendTime = row.sendTime;
    jrequest.get("/api/commendSend/getMessageBody",this.data.queryDialogData).then(res => {
      $(".j-dialog-content p span").html(res.data.vehicleNo);
      if (res.data.photoUrl === "") {
        $(".j-dialog-content .jdialog-row img").attr("src","../../img/statistics/vehiclePZDefault.jpg");
      } else {
        $(".j-dialog-content .jdialog-row img").attr("src",res.data.photoUrl);
      }
      
    })
  },
  getCheckPlatData(row) {
    this.data.queryDialogData.vehicleNo = "";
    this.data.queryDialogData.commandCode = row.commandCode;
    this.data.queryDialogData.sendTime = row.sendTime;
    jrequest.get("/api/commendSend/getMessageBody",this.data.queryDialogData).then(res => {
      $(".jdialog-row.dialog_check p:last-child span").html(res.data.infoContent);
      if (res.data.objectType === "1") {
        $(".jdialog-row.dialog_check p:first-child span").html("当前连接的下级平台");
      } else if (res.data.objectType === "2") {
        $(".jdialog-row.dialog_check p:first-child span").html("下级平台所属单一业户");
      }
    })
  },
  getCheckOwersData(row) {
    this.data.queryDialogData.vehicleNo = "";
    this.data.queryDialogData.commandCode = row.commandCode;
    this.data.queryDialogData.sendTime = row.sendTime;
    jrequest.get("/api/commendSend/getMessageBody",this.data.queryDialogData).then(res => {
      $(".jdialog-row.dialog_check p:last-child span").html(res.data.infoContent);
      if (res.data.objectType === "1") {
        $(".jdialog-row.dialog_check p:first-child span").html("当前连接的下级平台");
      } else if (res.data.objectType === "2") {
        $(".jdialog-row.dialog_check p:first-child span").html("下级平台所属单一业户");
      }
    })
  },
  /**
   * 综合查询 选择性调用方法 查询表格数据
   */
  queryTableData() {
    switch(this.data.pageNum) {
      case 1:
      this.getPlatTableData();
      break;
      case 2:
        this.getOwerTableData();
        break;
      case 3:
        this.getVehicTableData();
        break;
    }
  },
  /**
   * select设置
   */
  selectedValue:function(){
		var self=this;
		var optionArr=["全部","下发查岗","下发公告"];
		self.creatId("#interactionType",optionArr);
		var optionArr2=["全部","部级平台下发","下级平台上报"];
		self.creatId("#message_from",optionArr2);
    // var optionArr3=["全部","车辆单向监听","车辆拍照","车辆下发消息","行驶记录仪上报","车辆应急接入"];
    var optionArr3 = [{value:"0x9501",name:"车辆单向监听"},
    {value:"0x9502",name:"车辆拍照"},
    {value:"0x9503",name:"车辆文本下发"},
    {value:"0x9505",name:"车辆应急接入"},
    {value:"0x920A",name:"上报驾驶员身份信息"},
    {value:"0x9504",name:"上报车辆行驶路线"},
    {value:"0x9801",name:"车辆视频监控"},
    {value:"0x9301",name:"查岗请求"},
    {value:"0x9302",name:"平台间报文"},
    {value:"",name:"上报行驶记录仪信息"},
    {value:"",name:"上报车辆电子运单"}
    ];
    self.creatIdInfor("#message_type",optionArr3);
	},
	creatId:function(id,optionArr){
		$(id).html();
		var str="";
		$.each(optionArr,function (i) {
			str+="<option value='"+optionArr[i]+"'>"+optionArr[i]+"</option>"
		});
		$(id).html(str);
		$(id).comboSelect();
  },
  creatIdInfor:function(id,optionArr){
		$(id).html();
		var str="";
		$.each(optionArr,function (k,i) {
			str+="<option value='"+i.value+"'>"+i.name+"</option>"
		});
		$(id).html(str);
		$(id).comboSelect();
  },
  /**
   * 表格单元格添加列点击事件
   */
  operateFormatterVehicle:function(value, row, index){
    if (row.ackContent === "请求成功" && row.commandCode === "0x9502") {
      historyRecord.data.clpzFontColor = "#00B2FC";
      historyRecord.data.cursorType = "pointer";
    } else {
      historyRecord.data.clpzFontColor = "#fff";
      historyRecord.data.cursorType = "default";

    }
		return [
      `<span style="cursor: ${historyRecord.data.cursorType};color: ${historyRecord.data.clpzFontColor}" id="commandType">${value}</span>`
		].join('');
  },
  operateFormatterCheckPlatform:function(value, row, index) {
    if (row.ackContent === "请求成功" && row.commandCode === "0x9301") {
      historyRecord.data.ptcgFontColor = "#00B2FC";
      historyRecord.data.cursorType = "pointer";
    } else {
      historyRecord.data.ptcgFontColor = "#fff";
      historyRecord.data.cursorType = "default";
    }
    return [
      `<span style="cursor: ${historyRecord.data.cursorType};color: ${historyRecord.data.ptcgFontColor}" id="checkPlatform">${value}</span>`
		].join('');
  },
  operateFormatterCheckOwers:function(value, row, index) {
    if (row.ackContent === "请求成功" && row.commandCode === "0x9301") {
      historyRecord.data.yhcgFontColor = "#00B2FC";
      historyRecord.data.cursorType = "pointer";
    } else {
      historyRecord.data.yhcgFontColor = "#fff";
      historyRecord.data.cursorType = "default";
    }
    return [
      `<span style="cursor: ${historyRecord.data.cursorType};color: ${historyRecord.data.yhcgFontColor}" id="checkOwers">${value}</span>`
		].join('');
  },
  /**
   * 点击事件
   */
  btnEvent() {
    $(".message_type").hide();
    $(".message_from").hide();

    $(".tab_content").on("click","div",function() { // 顶部tab切换
      var index = $(this).index();
      $(".tab_content div").eq(index).addClass("active").siblings().removeClass("active")
      historyRecord.resetQueryData(); // 重置
      switch(index) {
        case 0:
          historyRecord.data.pageNum = 1;
          $(".platOwersVehName").html("平台");
          $(".platform_code").show();
          $(".message_type").hide();
          $(".message_from").hide();
          $(".interaction_type").show();
          historyRecord.getPlatTableData();
          break;
        case 1:
          historyRecord.data.pageNum = 2;
          $(".platOwersVehName").html("企业");
          $(".platform_code").hide();
          $(".message_type").hide();
          $(".message_from").hide();
          $(".interaction_type").show();
          historyRecord.getOwerTableData();
          break;
        case 2:
          historyRecord.data.pageNum = 3;
          $(".platOwersVehName").html("车牌号");
          $(".platform_code").hide();
          $(".message_type").show();
          $(".message_from").show();
          $(".interaction_type").hide();
          historyRecord.getVehicTableData();
          break;
      }
    })
    $(".searchHistory_btn").click(() => { // 查询
      historyRecord.queryTableData();
    })
    $(".resetHistory_btn").click(() => { // 重置
      historyRecord.resetQueryData();
    })

    $(".close-div.PZClose").click(function() { // 拍照模态框隐藏
      $("#photoDialog").hide();
      $(".j-dialog-content p span").html("");
      $(".j-dialog-content .jdialog-row img").attr("src","../../img/statistics/vehiclePZDefault.jpg");
    })
    $(".close-div.CGClose").click(function() { // 查岗模态框隐藏
      $("#cgDialog").hide();
      $(".jdialog-row.dialog_check p:first-child span").html("");
      $(".jdialog-row.dialog_check p:last-child span").html("");
    })
    $(".close-div.driverInfo").click(function() { // 驾驶员身份识别信息上报
      $("#driverInfoUP").hide();
    })
    $(".close-div.drivingRecordUP").click(function() {
      $("#drivingRecord").hide();
    })
  }
}


$(function() {
  historyRecord.initPage();
})